package com.huanbao.oil.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.huanbao.oil.app.R;
import com.huanbao.oil.app.commons.Arithmetic4Double;
import com.huanbao.oil.app.model.BaoJingResultModel;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class BaoJing_JiLuAdapter extends BaseAdapter {
    private LayoutInflater minflater;
    private Context context;
    private List<BaoJingResultModel> data;

    public BaoJing_JiLuAdapter(Context context, List<BaoJingResultModel> data) {
        super();
        this.minflater = LayoutInflater.from(context);
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        int size=0;
        if(data!=null){
            size= data.size();
        }
        return size;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
//            holder = new ViewHolder();
            convertView = minflater.inflate(R.layout.item_baojing_jilu, null);
            holder = new ViewHolder(convertView);//这句变化
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//		holder.themeId.setText(data.get(position));
//        holder.itemYunxingJilu3.setSelected(true);

//        holder.itemBaojingJilu1.setText(data.get(position).getDate());
        holder.itemBaojingJilu2.setText(data.get(position).getTime());
//        holder.itemBaojingJilu3.setText(data.get(position).getDate());
        holder.itemBaojingJilu4.setText(data.get(position).getAlarm_type());
        holder.itemBaojingJilu5.setText(Arithmetic4Double.keepOneByStr(data.get(position).getCur_value()));
        holder.itemBaojingJilu6.setText(Arithmetic4Double.keepOneByStr(data.get(position).getLevel_value()));
        holder.itemBaojingJilu7.setText(data.get(position).getAlarm_desc());


        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.item_baojing_jilu_1)
        TextView itemBaojingJilu1;
        @BindView(R.id.item_baojing_jilu_2)
        TextView itemBaojingJilu2;
        @BindView(R.id.item_baojing_jilu_3)
        TextView itemBaojingJilu3;
        @BindView(R.id.item_baojing_jilu_4)
        TextView itemBaojingJilu4;
        @BindView(R.id.item_baojing_jilu_5)
        TextView itemBaojingJilu5;
        @BindView(R.id.item_baojing_jilu_6)
        TextView itemBaojingJilu6;
        @BindView(R.id.item_baojing_jilu_7)
        TextView itemBaojingJilu7;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
